
<?php
 $songay = date('d-m-Y',strtotime($cuoithang)) - date('d-m-Y',strtotime($dauthang))+1;
 $sothuoctinh = count($thuoctinhs);
?>
<?php echo $this->Html->link(__('Xuất Excel', true), array('action' => 'laykqexcel'));?>
<table id ='tables'>
<tr>
<th rowspan=2>STT</th>
<th rowspan=2>Đơn vị</th>
<th rowspan=2>Nhân viên đa nhiệm</th>
<th rowspan=2>Mã kênh</th>
<th rowspan=2>Kênh</th>
<th rowspan=2>ĐT</th>
<th colspan=<?php echo $sothuoctinh?>>Hình ảnh điểm bán</th>
<th colspan=<?php echo $songay?>>Tần suất chăm sóc</th>
<th rowspan=2>Thông tin thị trường</th>
</tr>
<tr>
<?php foreach ($thuoctinhs as $valuett):?>
<th><?php echo $valuett?></th>
<?php endforeach;?>
<?php
$date = date('d-m-Y',strtotime($dauthang));
for($i=0;$i<$songay;$i++)
{
?>
<th><?php echo $date?></th>
<?php $date=date('d-m-Y',StrToTime('+1 days', strtotime($date))); }?>
</tr>

<?php
$stt = 0;
 foreach ($kenhinfo as $info)
{?>
<tr>
<td><?php echo ++$stt?></td>
<td><?php echo $info['Nhanvien']['Donvi']['madv']?></td>
<td><?php echo $info['Nhanvien']['tennv']?></td>
<td><?php echo $info['Kenh']['makenh']?></td>
<td><?php echo $info['Kenh']['tenkenh']?></td>
<td><?php echo $info['Kenh']['sdt']?></td>
<?php foreach ($thuoctinhs as $keytt=> $valuett):?>
<td><?php
	foreach($hinhanhdbs as $hinhanhdb)
		if($hinhanhdb['Hinhanhdb']['kenh_id']==$info['Kenh']['id'] && $hinhanhdb['Hinhanhdb']['thongtindb_id']==$keytt)
		{
			echo $hinhanhdb['Hinhanhdb']['noidung'];
			break;
		} 
 ?></td>
<?php endforeach;?>
<?php
$date = date('d-m-Y',strtotime($dauthang));
for($i=0;$i<$songay;$i++)
{
?>
<td><?php
$check=0;
		foreach ($chamsocs as $chamsoc)
		{
			if($chamsoc['Chamsockenh']['kenh_id']==$info['Kenh']['id'] && date('d-m-Y',strtotime($chamsoc['Chamsockenh']['ngaydi']))==$date)
			{
				echo $chamsoc[0]['solan'];
				break;
			}
		}
		
		?></td>
		<?php $date=date('d-m-Y',StrToTime('+1 days', strtotime($date))); }?>
<td>
<?php 
foreach($thongtintts as $thongtintt)
		if($thongtintt['Thitruongkenh']['kenh_id']==$info['Kenh']['id'])
		{
			echo '-' .$thongtintt[0]['thitruong'];
			break;
		}
?>
</td>
<?php  }?> 
</tr>
</table>